<template>
  <div class="table-view">
    <div class="table-title">
      <input v-focus v-if="isEdit" v-model="title" type="text" @blur="changeTitle" />
      <div v-else class="text editabled" @click="handleEdit">{{ tableAttr.title }}</div>
      <i v-if="!isEdit" class="icon iconfont" @click="handleEdit">&#xe6aa;</i>
      <i v-else class="icon iconfont" @click="handleEdit">&#xe6aa;</i>
    </div>
    <div class="table-content">
      <el-scrollbar height="100%">
        <div class="table-scroll">
          <VTable>
            <template #cell="{ tdId }">
              <FormItem :tdId="tdId" type="config-table" />
            </template>
          </VTable>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup lang="ts">
// 表格数据和方法
const { tableAttr, setTableAttr } = inject<{
  tableAttr: any
  setTableAttr: Function
}>('tables', {
  tableAttr: {},
  setTableAttr: () => {}
})
const isEdit = ref<boolean>(false)
const title = ref<string>('')
const handleEdit = () => {
  isEdit.value = true
  title.value = tableAttr.value.title
}
const changeTitle = () => {
  setTableAttr({
    title: title.value
  })
  isEdit.value = false
  title.value = ''
}
</script>

<style lang="scss" scoped>
.table-view {
  height: 100%;
  .table-title {
    width: 100%;
    font-size: 24px;
    padding: 20px 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    .icon {
      font-size: 24px;
      margin-left: 10px;
      cursor: pointer;
    }
  }
  .table-content {
    width: 100%;
    height: calc(100% - 100px);
    padding: 20px;
    box-sizing: border-box;
    .table-scroll {
      padding: 40px;
    }
  }
}
</style>
